package com.yxr.affairs;

import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Matrix;
import android.os.AsyncTask;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.utils.ViewPortHandler;
import com.thoughtworks.xstream.XStream;
import com.yxr.affairs.api.Constans1;
import com.yxr.affairs.base.BaseSwipeBackActivity1;
import com.yxr.affairs.utils.ToastUtil;
import com.yxr.affairs.utils.Utils;
import com.yxr.affairs.view.DoubleLineChatView;
import com.yxr.affairs.xtem.EncodeXstream;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import com.yxr.affairs.dt.Data;
import com.yxr.affairs.dt.Param1;
import com.yxr.affairs.dt.Storeditem;

import butterknife.BindView;

import static android.content.Context.MODE_PRIVATE;

public class DtActivity  extends BaseSwipeBackActivity1 {

    private int[] mDataLeft/*={1,2,3,4,5,6}*/;
    //    private int[] mDataRight = {151, 65, 280, 66, 105, 88, 198, 299, 45};
    private String[] mDataTextX;
    ///* = {"项目1", "项目2", "项目3", "项目4", "项目5", "项目6", "项目7", "项目8", "项目9"}*/
    private RelativeLayout settingrule_item,settingrule;
    private int mYear;
    private int mMonth;
    private int mDay;
    private  int mHoure;
    private  int mInute;
    private  int mSecond;

    private TextView activity_2,activity_xuan;
    private Button activity_btn;

    private    String i1s, i2s;
    private  String mHoure1,mInute1,mSecond1;
    final String[] str_color = {"全部医院","北京晶奇和-HSI5.0总院","测试医院1"};

    private   String Honst;
    private  String  time;
    private  String str;
    private ImageButton goback;

    ProgressDialog xh_pDialog;
    private TextView activity_4;
    private  BarChart hbcChart;
    int  so;
    @BindView(R.id.rv_invest3)
    RecyclerView rvInvest1;

     private RelativeLayout avtivity_jitong;


    private  RelativeLayout avtivity_jitong1;

    private LinearLayout ll_statistics_chart;
    private LinearLayout ll_statistics_list;
    private TextView tv_statistics_chart;
    private TextView tv_statistics_list;
    private  ArrayList<Storeditem> storeditems=new ArrayList<>();
    private MessageAdapter adapter;

    boolean isRequestSuccess = false;
    private LinearLayout activity_keshi;
    private ImageView iv_statistics_chart;
    private  ImageView iv_statistics_list;

    private String SoftVersion;
    private String DataServerIP;
    private String Key;
    private String DataServerPort;
    private String SoftName;
    private String mDeviceid;
    private String mUsercode;
    private String mUserpwd;
    private String mVersion;
    private String mHospitalid;


    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_dongtai;
    }

    @Override
    protected void initViews() {



        SharedPreferences sPreferences=getSharedPreferences("muser", MODE_PRIVATE);
        Key=sPreferences.getString("Key", "");
        DataServerIP=sPreferences.getString("DataServerIP", "");
        DataServerPort=sPreferences.getString("DataServerPort", "");
        mDeviceid=sPreferences.getString("mDeviceid", "");
        mUsercode=sPreferences.getString("mUsercode", "");
        mUserpwd=sPreferences.getString("mUserpwd", "");
        mVersion=sPreferences.getString("mVersion", "");
        mHospitalid=sPreferences.getString("mHospitalid", "");




        adapter  = new MessageAdapter(mContext,storeditems);
        rvInvest1.setLayoutManager(new LinearLayoutManager(DtActivity.this));
        rvInvest1.setAdapter(adapter);



        settingrule_item=(RelativeLayout)findViewById(R.id.settin);
        settingrule= (RelativeLayout) findViewById(R.id.settingrule);
        activity_2=(TextView)findViewById(R.id.activity_2);
        activity_xuan= (TextView) findViewById(R.id.activity_xuan);

        goback= (ImageButton) findViewById(R.id.goback);

        hbcChart= (BarChart) findViewById(R.id.bc_chart);

        ll_statistics_chart= (LinearLayout) findViewById(R.id.ll_statistics_chart);

        ll_statistics_list= (LinearLayout) findViewById(R.id.ll_statistics_list);

        tv_statistics_chart= (TextView) findViewById(R.id.tv_statistics_chart);

        tv_statistics_list= (TextView) findViewById(R.id.tv_statistics_list);

        iv_statistics_chart= (ImageView) findViewById(R.id.iv_statistics_chart);

        iv_statistics_list= (ImageView) findViewById(R.id.iv_statistics_list);

        activity_keshi= (LinearLayout) findViewById(R.id.activity_keshi);
        avtivity_jitong= (RelativeLayout) findViewById(R.id.avtivity_jitong);
        avtivity_jitong1= (RelativeLayout) findViewById(R.id.avtivity_jitong1);
      //  activity_4= (TextView) findViewById(R.id.activity_4);

        activity_xuan.setText("全部医院");




        settingrule_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSend();
            }
        });

        goback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });



        settingrule.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //   getxuan();
            }
        });



        //系统前一天的时间

        SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd");
        String cDate = df.format(new Date());
        Calendar c = Calendar.getInstance();
        Date date=null;
        try {
            date = new SimpleDateFormat("yy.MM.dd").parse(cDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        c.setTime(date);
        int day=c.get(Calendar.DATE);
        c.set(Calendar.DATE,day-1);

        String dayBefore=new SimpleDateFormat("yyyy.MM.dd").format(c.getTime());

        activity_2.setText(dayBefore);
        time=dayBefore;
        if (!Utils.isNetworkConnected(mContext)) {
            Toast.makeText(mContext, getString(R.string.network_hint), Toast.LENGTH_SHORT).show();
            return;
        }
        QueryAddressTask queryAddressTask = new QueryAddressTask();
        queryAddressTask.execute( time);

        initBarChart();


        ll_statistics_chart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                    avtivity_jitong.setVisibility(View.GONE);
                    avtivity_jitong1.setVisibility(View.VISIBLE);
                    hilightStatisticsListIndicatorView(true);
                    hilightStatisticsChartIndicatorView(false);
                    activity_keshi.setVisibility(View.GONE);


            }
        });

        ll_statistics_list.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                   avtivity_jitong.setVisibility(View.VISIBLE);
                    avtivity_jitong1.setVisibility(View.GONE);
                    activity_keshi.setVisibility(View.VISIBLE);
                    hilightStatisticsListIndicatorView(false);
                    hilightStatisticsChartIndicatorView(true);


            }
        });
    }

    private void hilightStatisticsListIndicatorView(boolean hilight) {
        if (!hilight) {
            iv_statistics_chart.setImageResource(R.mipmap.activity_da1);
            tv_statistics_chart.setTextColor(getResources().getColor(R.color.black_3));
        } else {

            iv_statistics_chart.setImageResource(R.mipmap.activity_da2);
            tv_statistics_chart.setTextColor(getResources().getColor(R.color.colorPrimary));

        }

    }

    private void hilightStatisticsChartIndicatorView(boolean hilight) {
        if (!hilight) {
            iv_statistics_list.setImageResource(R.mipmap.activity_da3);
            tv_statistics_list.setTextColor(getResources().getColor(R.color.black_3));
        } else {
            iv_statistics_list.setImageResource(R.mipmap.activity_da4);
            tv_statistics_list.setTextColor(getResources().getColor(R.color.colorPrimary));
            QueryAddressTask queryAddressTask = new QueryAddressTask();
            queryAddressTask.execute( time);

        }
    }
    private String getData(String param){
        String    result = null;
        String WSDL_URI = "http://"+DataServerIP+":"+DataServerPort+"/soap/IHyWebServer";//wsdl 的uri
        String namespace = "urn:HyWebServerIntf-IHyWebServer";//namespace
        String methodName = "HyWebServiceIntfMethod";//要调用的方法名称

        SoapObject request = new SoapObject(namespace, methodName);

        String de= "<hywebserviceroot>" +
                "<funname>GetMbUserFunction</funname>" +
                "<hospitalid>"+mHospitalid+"</hospitalid>" +
                "    <key>"+Key+"</key>" +
                "    <deviceid>"+mDeviceid+"</deviceid>" +
                "    <usercode>"+mUsercode+"</usercode>" +
                "    <userpwd>"+mUserpwd+"</userpwd>" +
                "    <version>"+mVersion+"</version>" +
                "    <params>" +
                "     <param1><sFunName>GetMZGHRC</sFunName></param1>" +
                "     <param2><dL_RQ>"+time+" 00:00:00"+"</dL_RQ><sHospitalID></sHospitalID><LX>2</LX></param2>"+
                "    </params>" +
                "</hywebserviceroot>";

        request.addProperty("aXml", de);
        //创建SoapSerializationEnvelope 对象，同时指定soap版本号(之前在wsdl中看到的)

        try {
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER11);
            envelope.bodyOut = request;//由于是发送请求，所以是设置bodyOut
            envelope.dotNet = true;//由于是.net开发的webservice，所以这里要设置为true
            HttpTransportSE httpTransportSE = new HttpTransportSE(WSDL_URI);
            httpTransportSE.debug = false;
            httpTransportSE.call("urn:HyWebServerIntf-IHyWebServer#HyWebServiceIntfMethod", envelope);//调用

            // 获取服务器响应返回的SOAP消息
            SoapObject object = (SoapObject) envelope.bodyIn;
            result = object.getProperty(0).toString();
            //     Log.e("DSDSDS", result);
            return result;

        } catch (Exception e) {
            Log.e("TAG", "getData: "+e );
        }
        return result;

    }


    private List<String> XData = new ArrayList<>();
    private void initBarChart() {


        hbcChart.setNoDataTextColor(getResources().getColor(R.color.colorPrimary));
        hbcChart.setDrawBarShadow(false);

        hbcChart.setDrawValueAboveBar(true);

        hbcChart.getDescription().setEnabled(false);

        hbcChart.setMaxVisibleValueCount(60);

        hbcChart.setPinchZoom(false);

        hbcChart.setDrawGridBackground(false);

        //自定义设置横坐标
        IAxisValueFormatter xValueFormatter = new IAxisValueFormatterImpl(XData);
    //设置不显示网格线，保留水平线
         XAxis xAxis = hbcChart.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setDrawAxisLine(false);
        xAxis.setDrawGridLines(false);
        xAxis.setGridLineWidth(1);
    //设置为true当一个页面显示条目过多，X轴值隔一个显示一个
        xAxis.setGranularityEnabled(true);
    //设置最小间隔，防止当放大时，出现重复标签。
        xAxis.setGranularity(1f);
    //一个界面显示6个Lable。那么这里要设置7个
        xAxis.setLabelCount(7);
    //将自定义的横坐标设置上去
        xAxis.setValueFormatter(xValueFormatter);
    //设置X轴字体显示角度
        xAxis.setLabelRotationAngle(90f);
        xAxis.setTextSize(10f);

        hbcChart.invalidate();
        Matrix mMatrix=new Matrix();
        mMatrix.postScale(1.3f, 1f);
        hbcChart.getViewPortHandler().refresh(mMatrix, hbcChart, false);
        hbcChart.animateY(800);

        YAxis yl = hbcChart.getAxisLeft();
//        yl.setTypeface(mTfLight);
        yl.setDrawAxisLine(true);
        yl.setDrawGridLines(false);
        yl.setAxisMinimum(0f);
        YAxis yr = hbcChart.getAxisRight();
        yr.setDrawAxisLine(true);
        yr.setDrawGridLines(false);
        yr.setAxisMinimum(0f);

        hbcChart.setFitBars(true);
        hbcChart.animateY(800);


        Legend l = hbcChart.getLegend();
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
        l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
        l.setDrawInside(false);
        l.setFormSize(8f);
        l.setXEntrySpace(4f);
        l.setWordWrapEnabled(true);

    }


    public  class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHolder>{


        private ArrayList<Storeditem>  storeditems;
        private Context mContext;
        public MessageAdapter( Context context, ArrayList<Storeditem> dataLists){

            mContext=context;
            this.storeditems=dataLists;
        }

        public void  setData(ArrayList<Storeditem> storeditems){

         this.storeditems=storeditems;
        }
        private Context getContext() {
            return mContext;
        }

        @Override
        public MessageAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

            Context context = parent.getContext();
            LayoutInflater inflater = LayoutInflater.from(context);

            View contactView = inflater.inflate(R.layout.activity_dtitem, parent, false);

            MessageAdapter.ViewHolder viewHolder = new MessageAdapter.ViewHolder(contactView);
            return viewHolder;

        }

        @Override
        public void onBindViewHolder(MessageAdapter.ViewHolder holder, int position) {


            holder.TextView1.setText(storeditems.get(position).getsBRKSID());
            holder.TextView2.setText(storeditems.get(position).getsBRKSMC());
            holder.TextView3.setText(storeditems.get(position).getiSL());
        }

        @Override
        public int getItemCount() {
            return storeditems.size();
        }
        public class ViewHolder extends RecyclerView.ViewHolder {


            public TextView TextView1;
            public TextView TextView2;
            public TextView TextView3;


            public ViewHolder(View itemView) {
                super(itemView);

                TextView1 = (TextView)itemView.findViewById(R.id.TextView1);
                TextView2 = (TextView)itemView.findViewById(R.id.TextView2);
                TextView3 = (TextView)itemView.findViewById(R.id.TextView3);
            }
        }
    }


        class QueryAddressTask extends AsyncTask<String, Integer, String> {
        @Override
        protected void onPreExecute() {
            xh_pDialog = new ProgressDialog(DtActivity.this);

            // 设置进度条风格，风格为圆形，旋转的
            xh_pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

            // 设置ProgressDialog 标题
            xh_pDialog.setTitle("正在加载，请稍等");

            xh_pDialog.setIndeterminate(false);

            // 设置ProgressDialog 是否可以按退回键取消
            xh_pDialog.setCancelable(true);

            // 让ProgressDialog显示
            xh_pDialog.show();

        }

        @Override
        protected String doInBackground(String... params) {
            // 查询手机号码（段）信息*/
            String    result = null;
            try {
                result = getData(params[0]);
                Log.d("ASADDD",result);

            } catch (Exception e) {

                e.printStackTrace();
            }
            //将结果返回给onPostExecute方法
            return result;
        }

        @Override
        //此方法可以在主线程改变UI
        protected void onPostExecute(String result) {
            // 将WebService返回的结果显示在TextView中

            xh_pDialog.dismiss();

            if (result != null) {
                XStream xStream2 = new EncodeXstream("1.0", "gb2312");
                xStream2.alias("result", Data.class);
                xStream2.useAttributeFor(Param1.class, "size");
                xStream2.addImplicitCollection(Param1.class, "storeditems");

                xStream2.alias("storeditem", Storeditem.class);
                storeditems.clear();
                Data data = (Data) xStream2.fromXML(result);

                Log.e("TAG1", "status: " + data.getStatus());
                Log.e("TAG1", "errorinfo: " + data.getErrorinfo());
                Log.e("TAG1","successinfo"+data.getSuccessinfo());
                Log.e("TAG1", "param1 size: " + data.getSuccessinfo().getParam1().getSize());



                try {

                    if(data.getSuccessinfo().getParam1().getStoreditems() != null){

                        storeditems.clear();
                        storeditems.addAll((ArrayList<Storeditem>) data.getSuccessinfo().getParam1().getStoreditems());
                        adapter.setData(storeditems);
                        adapter.notifyDataSetChanged();


                        storeditems = (ArrayList<Storeditem>) data.getSuccessinfo().getParam1().getStoreditems();

                        mDataLeft=new int[storeditems.size()];//创建一个和list长度一样的数组
                        for(int i=0;i<storeditems.size();i++){
                            mDataLeft[i]=Integer.parseInt(storeditems.get(i).getiSL());//数组赋值了。
                            Log.e("ADADAAD", String.valueOf(mDataLeft[i]));
                        }
                        mDataTextX= new String[storeditems.size()];
                        for (int i=0;i<storeditems.size();i++){
                            mDataTextX[i]=storeditems.get(i).getsBRKSMC();
                            Log.e("ADADAAD",String.valueOf(mDataTextX[i]));

                            for (Storeditem s : storeditems) {
                                Log.e("TAG1", "patient_id: " + s.getiSL());
                                Log.e("TAG1", "dealno: " + s.getsBRKSID());
                                Log .e("TAG1", "billno: " + s.getsBRKSMC());


                            }

                        }
                        if(mDataLeft.length>0){


                            if (hbcChart!=null) {
                                hbcChart.clear();
                                hbcChart.getAxisLeft().resetAxisMaximum();
                                hbcChart.getAxisRight().resetAxisMaximum();
                            }
                            //纵坐标数值
                            ArrayList<BarEntry> yVals = new ArrayList<BarEntry>();
                            for (int i = 0; i< mDataLeft.length; i++) {
                                yVals.add(new BarEntry(i,mDataLeft[i]));
                            }
                            for (int j = 0; j < mDataTextX.length; j++) {
                                XData.add(mDataTextX[j]);
                            }

                            setData(yVals);

                            hbcChart.notifyDataSetChanged();
                            hbcChart.invalidate();
                        }

                    }else{

                        ToastUtil.toast(mContext,"暂时没有数据");
                        avtivity_jitong.setVisibility(View.GONE);
                        hbcChart.clear();
                        hbcChart.setNoDataText("您暂无数据,请添加数据...");

                    }


                } catch (Exception e) {

                    e.printStackTrace();
                }


            }else {
                ToastUtil.toast(mContext,"网络异常,请检查!");
            }

        }
    }

    private void setData(List<BarEntry> Y) {


        ArrayList<BarEntry> yVals = new ArrayList<BarEntry>();
        for (int j = 0; j < Y.size(); j++) {
            yVals.add(new BarEntry(j,mDataLeft[j]));
        }
        BarDataSet mBarDataSet = new BarDataSet(yVals, "柱状图人数");

        // 如果是0f，那么柱状图之间将紧密无空隙的拼接在一起形成一片。

        // 柱状图柱的颜色
        mBarDataSet.setColor(Color.parseColor("#0096d5"));

        // 当柱状图某一柱被选中时候的颜色
    //    mBarDataSet.setHighLightColor(Color.YELLOW);

        mBarDataSet.setValueFormatter(new IValueFormatter() {

            @Override
            public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
                DecimalFormat decimalFormat = new DecimalFormat(".0");
                String s = decimalFormat.format(value);
                return s;
            }
        });

        BarData mBarData = new BarData(mBarDataSet);
    //    mBarData.setValueFormatter(new DoubleValueFormatter());
        mBarData.setValueTextSize(13f);
        mBarData.setBarWidth(0.4f);
        hbcChart.setData(mBarData);

        hbcChart.invalidate();
    }
    /* public  void  getxuan(){


         new AlertDialog.Builder(this)
                 .setTitle("")
                 .setSingleChoiceItems(str_color, 0, new DialogInterface.OnClickListener() {
                     @Override
                     public void onClick(DialogInterface dialog, int which) {

                         activity_xuan.setText( str_color[which]);
                    //     Toast.makeText(UIActivity2.this, "选中了" + str_color[which], Toast.LENGTH_SHORT).show();

                         //移除
                         dialog.dismiss();
                     }
                 })
                 .setNeutralButton("", null)
                 .show();


     }*/
    public void getSend(){


        Calendar  ca = Calendar.getInstance();
        mYear = ca.get(Calendar.YEAR);
        mMonth = ca.get(Calendar.MONTH);
        mDay = ca.get(Calendar.DAY_OF_MONTH);

        // 获取当前的小时数
        mHoure = ca.get(Calendar.HOUR_OF_DAY);
        // 获取当前的分钟数
        mInute = ca.get(Calendar.MINUTE);
        mSecond  = ca.get(Calendar.SECOND);

        new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {


                if (i1 < 9) {
                    i1s = "0" + (i1 + 1);
                } else {
                    i1s = "" + (i1 + 1);
                }


                if (i2 < 10) {
                    i2s = "0" + i2;
                } else {
                    i2s = "" + i2;
                }

                Log.e("birthId", (i + "" + i1s + "-" + "" + i2));


                if (mHoure < 10) {
                    mHoure1 = "0" + mHoure;
                } else {
                    mHoure1 = "" + mHoure;
                }
                if (mInute < 10) {
                    mInute1 = "0" + mInute;
                } else {
                    mInute1 = "" + mInute;
                }
                if (mSecond < 10) {
                    mSecond1 = "0" + mSecond;
                } else {
                    mSecond1 = "" + mSecond;
                }



                activity_2.setText(i + "." + i1s + "." + i2s);
                 time=i + "." + i1s + "." + i2s;
                 Log.e("FAFAFAF",time);

                if (!Utils.isNetworkConnected(mContext)) {
                    Toast.makeText(mContext, getString(R.string.network_hint), Toast.LENGTH_SHORT).show();
                    return;
                }
                QueryAddressTask queryAddressTask = new QueryAddressTask();
                queryAddressTask.execute( time);
            }
                //   activity_2.setText((i +i1s+i2s+mHoure+mInute+mSecond).format("%Y-%m-%d %H:%M:%S"));



        }, mYear, mMonth, mDay).show();


        Log.i("birthday2", mYear + "--" + mMonth + "--" + Integer.parseInt(String.valueOf(mDay-1)));
    }
    @Override
    protected void updateViews(boolean isRefresh) {


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (xh_pDialog != null){
            xh_pDialog.dismiss();
            xh_pDialog = null;
        }
    }
    @Override
    protected void onError_(Throwable e) {

    }

    @Override
    protected void onCancel_() {

    }
    class IAxisValueFormatterImpl implements IAxisValueFormatter{

        private List<String> XData =  new ArrayList<>();

        public IAxisValueFormatterImpl(List<String> XData) {
            this.XData = XData;
        }

        @Override
        public String getFormattedValue(float value, AxisBase axis) {

            int index = (int) value;
            if (index < 0 || index >= XData.size()) {
                return "";
            } else {
                return XData.get(index) + "";
            }
        }
    }
}
